package com.boom.controller;

import com.boom.mapper.ProviderMapper;
import com.boom.pojo.Bill;
import com.boom.pojo.Provider;
import com.boom.service.BillService;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/bill")
@Controller
public class BillController {


    @Resource
    private ProviderMapper providerMapper;

    @Resource
    private BillService billService;

    @RequestMapping("/list.html")
    public String list(Model model, @RequestParam(required = false)String queryProductName, @RequestParam(required = false)String queryProviderId, @RequestParam(required = false)String queryIsPayment){
        Bill bill=new Bill();
        if (queryProductName!=null && queryProductName!=""){
            bill.setProductName(queryProductName);
        }
       if (queryProviderId!=null && queryProviderId!=""){
           bill.setProviderId(Integer.parseInt(queryProviderId));
       }
       if (queryIsPayment!=null && queryIsPayment!=""){
           bill.setIsPayment(Integer.parseInt(queryIsPayment));
       }

       List<Provider> providerList=providerMapper.selectList(null);

        List<Bill> list=billService.getBillList(bill);
        model.addAttribute("billList",list);
        model.addAttribute("providerList",providerList);
        return "billlist";
    }
}

